home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2001 September / PC-WELT 9-2001.ISO / software / hw / brennen / flask_src.exe / Audio / MPEG / MPEGDec.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-15  |  2.3 KB  |  100 lines

  1. /* 
  2.  *  MPEGDec.cpp  -  MPEG audio decoding
  3.  *
  4.  *    Copyright (C) Alberto Vigata - January 2000 - ultraflask@yahoo.com
  5.  *
  6.  *  This file is part of FlasKMPEG, a free MPEG to MPEG/AVI converter
  7.  *    
  8.  *  FlasKMPEG is free software; you can redistribute it and/or modify
  9.  *  it under the terms of the GNU General Public License as published by
  10.  *  the Free Software Foundation; either version 2, or (at your option)
  11.  *  any later version.
  12.  *   
  13.  *  FlasKMPEG is distributed in the hope that it will be useful,
  14.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  *  GNU General Public License for more details.
  17.  *   
  18.  *  You should have received a copy of the GNU General Public License
  19.  *  along with GNU Make; see the file COPYING.  If not, write to
  20.  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  21.  *
  22.  */
  23.  
  24. #include "MPEGDec.h"
  25.  
  26. //////////////////////////////////////////////////////////////////////
  27. // Construction/Destruction
  28. //////////////////////////////////////////////////////////////////////
  29.  
  30. CMPEGDec::CMPEGDec()
  31. {
  32.  
  33. }
  34.  
  35. CMPEGDec::~CMPEGDec()
  36. {
  37.  
  38. }
  39. int CMPEGDec::Start()
  40. {
  41.     in_ptr     =0;
  42.     frame_size =0;
  43.     if( (decoder=CreateAMPDecoder()) ){
  44.         decoder->Init();
  45.         decoder->setSource(this);
  46.         return 1;
  47.     }
  48.     else
  49.         return 0;
  50. }
  51.  
  52. int CMPEGDec::Stop()
  53. {
  54.     return 0;
  55. }
  56.  
  57. // Audio decoder data reader
  58. int CMPEGDec::read(void *buffer, int bytes){
  59.     int bytes_to_read;
  60.  
  61.     if(bytes > (frame_size - in_ptr) ){
  62.         bytes_to_read = frame_size - in_ptr;
  63.     }
  64.     else
  65.         bytes_to_read = bytes;
  66.     memcpy(buffer, &frame_data[in_ptr], bytes_to_read);
  67.     in_ptr += bytes_to_read;
  68.  
  69.     return bytes_to_read;
  70. }
  71.  
  72. int CMPEGDec::decodeFrame(ui8 *pcm_samples, ui8 *frame_data, ui32 frame_size)
  73. {
  74.     AMPStreamInfo pasi;
  75.     int i;
  76.     in_ptr           = 0;
  77.     this->frame_size = frame_size;
  78.     this->frame_data = frame_data;
  79.  
  80.     decoder->Reset();
  81.     decoder->ReadHeader();
  82.  
  83.     decoder->getStreamInfo(&pasi);
  84.     if(pasi.fStereo)
  85.         decoder->setDestination((short *)pcm_samples);
  86.     else
  87.         decoder->setDestination(temp_buffer);
  88.  
  89.     // Convert mono to stereo
  90.     if(decoder->DecodeFrame())
  91.     {
  92.         if(!pasi.fStereo)
  93.             for(i=0; i<FRAME_SAMPLES*2; i++)
  94.                 ((short *)pcm_samples)[i] = temp_buffer[i>>1];
  95.         return 1;
  96.     }
  97.     else
  98.         return 0;
  99. }
  100.